﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Data.Linq.Mapping;
using System.Data.Linq;

namespace Srs.Sample.Services
{
    [DataContract]
    public class Customer
    {
        private int? _id;
        private string _name;
        private Binary _version;

        #region Properties

        [DataMember]
        public int? ID
        {
            get { return _id; }
            set { _id = value; }
        }

        [DataMember]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        [DataMember]
        public Binary Version
        {
            get { return _version; }
            set { _version = value; }
        }

        #endregion

        public Customer () 
        { 
        }

        public Customer (Sample_Customer sc)
        {
            _id = sc.ID;
            _name = sc.Name;
            _version = sc.Version;
        }

        public Customer(Customers sc)
        {
            _id = sc.ID;
            _name = sc.Name;
            _version = sc.Version;
        }

        internal Sample_Customer ToDatabaseVersion ()
        {
            Sample_Customer sc = new Sample_Customer();
            sc.ID = (_id == null) ? 0 : _id.Value;
            sc.Name = _name;
            sc.Version = _version;
            return sc;
        }

        internal static List<Customer> Convert (IQueryable<Sample_Customer> query)
        {
            List<Customer> returnList = new List<Customer>();

            foreach (var entity in query)
                returnList.Add(new Customer(entity));

            return returnList;
        }

        internal static List<Customer> Convert(IQueryable<Customers> query)
        {
            List<Customer> returnList = new List<Customer>();

            foreach (var entity in query)
                returnList.Add(new Customer(entity));

            return returnList;
        }


    }
}
